package cn.tedu.mvc;
//SpringMVC解析get请求参数
import org.junit.Test;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
//负责接受请求做出响应
@RequestMapping("get")
//规定了浏览器的访问方式
public class GetController {
    //http://localhost:8080/car/insert?id=1&name=小明&age=18&price=9.9&type=911 Gt3
    @RequestMapping("param4")
    public car param4(car c){
        return c;
    }
    @RequestMapping("param3")
    public String param3(int id, String name, String age,double price) {
        return "<h1>"+id + " " + name + " "+age+" "+price;
    }
    @RequestMapping("param")
    public String param(int id,String name,String age){
        return "<h1>您的请求参数里id="+id+",您的请求参数里name="+name+",您的请求参数里age="+age;
    }
    @RequestMapping("param2")
    public void param2(int id,String name){
        System.out.println(id);
        System.out.println(name);
    }

    @Test//单元测试方法
    public void  get1(){
        String url="http://localhost:8080/car/insert?id=1&name=张三&age=18";
        String[] a = url.split("\\?")[1].split("&");
        for (String s:a){
            System.out.println(s);
            String data = s.split("=")[1];
            System.out.println(data);
        }
    }
}
